package one.stand.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import one.stand.aop.ApiController;
import one.stand.model.ResultModel;
import one.stand.request.*;
import one.stand.response.CustomerResponse;
import one.stand.response.GetCustomerInfoResponse;
import one.stand.response.InputDealMoneyResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 */
@RequestMapping("crmApi/customer")
@RestController
@Api(description = "客户模块")
public class CustomerController extends BaseController {

    @ApiOperation(value = "存为客户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerState", value = "1:独占客户 2:共享客户 3:成单客户", required = true, paramType = "Long"),
            @ApiImplicitParam(name = "lableIds", value = "标签id", required = true, paramType = "Long[]"),
            @ApiImplicitParam(name = "cardId", value = "名片id", required = true, paramType = "Long"),
    })
    @ApiController(isLogin = true, company = true,card = true,paramClass = CustomerRequest.class)
    @PostMapping("addCustomer")
    public ResultModel<Boolean> addCustomer(@RequestAttribute CustomerRequest request) {
        return crmFegin.addCustomer(request);
    }

    @ApiOperation(value = "客户类型分组统计")
    @ApiController(isLogin = true, company = true,card = true,paramClass = CustomerRequest.class)
    @PostMapping("countCustomer")
    public ResultModel<List<CustomerResponse>> countCustomer(CustomerRequest request,@RequestAttribute TokenRequest tokenRequest) {
        BeanUtils.copyProperties(tokenRequest,request);
        return crmFegin.countCustomer(request);
    }

    @ApiOperation(value = "客户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "customerState", value = "1:独占客户 2:共享客户 3:成单客户,4客户总池，5总的独占客户", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "lableIds", value = "标签id", paramType = "Integer[]"),
            @ApiImplicitParam(name = "name", value = "客户名", paramType = "String"),
            @ApiImplicitParam(name = "cardId", value = "员工Id", paramType = "Integer"),
            @ApiImplicitParam(name = "type", value = "1个人数据2企业数据", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true, company = true,card = true,paramClass = CustomerRequest.class)
    @PostMapping("getCustomer")
    public ResultModel<List<CustomerResponse>> getCustomer(@RequestAttribute CustomerRequest request) {
        return crmFegin.getCustomer(request);
    }

    @ApiOperation(value = "获取客户信息")
    @ApiImplicitParam(name = "cardId", value = "名片id", required = true, paramType = "Integer")
    @ApiController(isLogin = true, company = true,card = true,paramClass = CustomerRequest.class)
    @PostMapping("getCustomerInfo")
    public ResultModel<GetCustomerInfoResponse> getCustomerInfo(@RequestAttribute CustomerRequest request) {
        return crmFegin.getCustomerInfo(request.getCardId().longValue());
    }
    @ApiOperation(value = "修改客户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerId", value = "客户id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "cardId", value = "名片id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "phone", value = "电话", required = true, paramType = "String"),
            @ApiImplicitParam(name = "name", value = "姓名", required = true, paramType = "String"),
            @ApiImplicitParam(name = "personalWx", value = "个人微信", paramType = "String"),
            @ApiImplicitParam(name = "companyWx", value = "企业微信", paramType = "String"),
            @ApiImplicitParam(name = "email", value = "邮箱", paramType = "String"),
            @ApiImplicitParam(name = "position", value = "职位", paramType = "String"),
            @ApiImplicitParam(name = "companyId", value = "公司id", paramType = "String"),
            @ApiImplicitParam(name = "createCompanyName", value = "公司名称", paramType = "String"),
            @ApiImplicitParam(name = "customerRemark", value = "备注", paramType = "String"),
            @ApiImplicitParam(name = "lableIds", value = "标签", paramType = "Integer[]"),
            @ApiImplicitParam(name = "customerState", value = "1:独占客户 2:共享客户 3:成单客户", required = true, paramType = "String"),
            @ApiImplicitParam(name = "turnoverAmount", value = "成交金额", paramType = "String"),
            @ApiImplicitParam(name = "remark", value = "成交金额备注", paramType = "String"),
    })
    @ApiController(isLogin = true, company = true,card = true,paramClass = CustomerRequest.class)
    @PostMapping("updCustomer")
    public ResultModel<Boolean> updCustomer(@RequestAttribute CustomerRequest request) {
        return crmFegin.updCustomer(request);
    }

    @ApiOperation(value = "获取员工客户列表")
    @ApiController(isLogin = true, company = true,card = true,paramClass = CustomerRequest.class)
    @PostMapping("getCustomerList")
    public ResultModel<List<CustomerResponse>> getCustomerList(@RequestAttribute CustomerRequest request,@RequestAttribute TokenRequest tokenRequest) {
        BeanUtils.copyProperties(tokenRequest,request);
        return crmFegin.getCustomerList(request);
    }

    @ApiOperation(value = "成交记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "customerId", value = "客户id", required = true, paramType = "Integer")
    })
    @PostMapping("getInputDealList")
    @ApiController(isLogin = true, company = true,card = true,paramClass = InputDealMoneyRequest.class)
    public ResultModel<List<InputDealMoneyResponse>> getInputDealList(@RequestAttribute InputDealMoneyRequest request) {
        return crmFegin.getInputDealList(request);
    }

    @PostMapping("inputDealMoney")
    @ApiOperation(value = "录入成交金额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "inputDealId", value = "录入表id", paramType = "Integer"),
            @ApiImplicitParam(name = "customerId", value = "客户id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "money", value = "录入金额", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "remark", value = "录入备注", required = true, paramType = "String"),
            @ApiImplicitParam(name = "photos", value = "录入图片", required = true, paramType = "String"),
    })
    @ApiController(isLogin = true, company = true,card = true,paramClass = InputDealMoneyRequest.class)
    public ResultModel<Boolean> inputDealMoney(@RequestAttribute InputDealMoneyRequest request) {
        return crmFegin.inputDealMoney(request);
    }

    @ApiOperation(value = "手动创建客户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "电话", required = true, paramType = "String"),
            @ApiImplicitParam(name = "name", value = "姓名", required = true, paramType = "String"),
            @ApiImplicitParam(name = "userId", value = "客户ID（如果是存为客户，必传）", paramType = "Integer"),
            @ApiImplicitParam(name = "personalWx", value = "个人微信", paramType = "String"),
            @ApiImplicitParam(name = "companyWx", value = "企业微信", paramType = "String"),
            @ApiImplicitParam(name = "email", value = "邮箱", paramType = "String"),
            @ApiImplicitParam(name = "position", value = "职位", paramType = "String"),
            @ApiImplicitParam(name = "companyId", value = "公司id", paramType = "String"),
            @ApiImplicitParam(name = "createCompanyName", value = "公司名称", paramType = "String"),
            @ApiImplicitParam(name = "customerRemark", value = "备注", paramType = "String"),
            @ApiImplicitParam(name = "lableIds", value = "标签", required = true, paramType = "Integer[]"),
            @ApiImplicitParam(name = "customerState", value = "1:独占客户 2:共享客户 3:成单客户", required = true, paramType = "String"),
            @ApiImplicitParam(name = "turnoverAmount", value = "成交金额", paramType = "String"),
            @ApiImplicitParam(name = "remark", value = "成交金额备注", paramType = "String"),
    })
    @ApiController(isLogin = true, company = true,card = true,paramClass = CustomerRequest.class)
    @PostMapping("manualAdd")
    public ResultModel<Boolean> manualAdd(@RequestAttribute CustomerRequest request) {
        return crmFegin.manualAdd(request);
    }

    @ApiOperation(value = "修改客户标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerId", value = "客户id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "lableIds", value = "标签id", required = true, paramType = "Integer[]")
    })
    @PostMapping("updCustomerLabel")
    @ApiController(isLogin = true, company = true,card = true,paramClass = CustomerRequest.class)
    public ResultModel<String> updCustomerLabel(@RequestAttribute CustomerRequest request) {
        return crmFegin.updCustomerLabel(request);
    }

    @ApiOperation(value = "修改客户共享范围")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerId", value = "客户id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "customerState", value = "1:独占客户 2:共享客户 3:成单客户", required = true, paramType = "Integer")
    })
    @PostMapping("updCustomerState")
    @ApiController(isLogin = true, company = true,card = true,paramClass = CustomerRequest.class)
    public ResultModel<String> updCustomerState(@RequestAttribute CustomerRequest request) {
        return crmFegin.updCustomerState(request);
    }

    @PostMapping("/addFormId")
    @ApiOperation(value = "用户保存formId")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "formId", value = "formId", required = true, paramType = "String"),
            @ApiImplicitParam(name = "type", value = "1:user端,2:crm端", required = true, paramType = "Integer"),
    })
    @ApiController(isLogin = true, company = true,card = true,paramClass = UserRequest.class)
    public ResultModel<Integer> addFormId(@RequestAttribute UserRequest request){
        return userFegin.addFormId(request);
    }
}
